package com.itqf.factory;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.FactoryBean;

import java.io.InputStream;

/**
 * @Description: 构建复杂对象
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/13
 * @Time: 下午5:26
 */
public class MySqlSessionFactoryBean implements FactoryBean<SqlSessionFactory> {
    @Override
    public SqlSessionFactory getObject() throws Exception {

        SqlSessionFactoryBuilder sqlSessionFactoryBuilder =
                new SqlSessionFactoryBuilder();

        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");


        return sqlSessionFactoryBuilder.build(is);
    }

    @Override
    public Class<?> getObjectType() {
        return SqlSessionFactory.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }
}
